﻿<?php
session_start();
include("../../corePage/common.php");
header('Content-type:application/json;charset=UTF-8');
header("Access-Control-Allow-Origin: $domainName");
#获取用户名密码
$sys_username = trims($_REQUEST['sys_username']);
$sys_password = trims($_REQUEST['sys_password']);
$username = trims($_REQUEST['userName']);
$password = trims($_REQUEST['password']);
$nickname = trims($_REQUEST['nickname']);
$level = $_REQUEST['level'];   //数字
$email = $_REQUEST['email'];
$remarks = "";
$sys_username = "admin";
$sys_password = "admin";
$username = trims("  w1   w ");
$password = "qq";
$nickname = "dsa";
$level = 123;   //数字
$remarks = "";
#验证用户权限级别
$userObject = null;
$sys_level = null;
if(isset($sys_username) && isset($sys_password) ){
	$sql="select * from ".$database_prefix."_".$userTableName." where ".$username_field." = '$sys_username' and ".$password_field." = '$sys_password'";
	$userObject = select_Object($sql);
}elseif(isset($_SESSION['sys_level'])){
	$sys_level = $_SESSION['sys_level'];
}else{
	#未登录
	echo '{"status":"error","errorCode":"10"}';
	return false;
}	
if($userObject || $sys_level){
	#权限大于等于1023
	if(isset($userObject)){
		$sys_level = $userObject['level'];
	}
	if((int)$sys_level  >= 1023){
		$sql="select * from ".$database_prefix."_".$userTableName." where ".$username_field." = '$username' and level < '$sys_level'";
		$userObject = select_Object($sql);
		if($userObject){
			#用户名已存在[110]
			echo '{"status":"error","errorCode":"110"}';
		}else{
			if($username != "" && $password != ""){
				if(!isset($level)){
					$level = 0;
				}
				$sql="insert into  ".$database_prefix."_".$userTableName."(id,".$username_field.",".$password_field.",nickname,level,email,remarks) values(null,'$username','$password','$nickname','$level','$email','$remarks') ";
				$rows = insert_Object($sql);
				if($rows>0){
					echo '{"status":"success"}';
				}else{
					#插入失败[111]
					echo '{"status":"error","errorCode":"111"}';
				}
			}else{
				#用户名或密码不能为空[112]
				echo '{"status":"error","errorCode":"112"}';
			}
		}
	}else{
		#权限不够[113]
		echo '{"status":"error","errorCode":"113"}';
	}
}else{
	#用户不存在[114]
	echo '{"status":"error","errorCode":"114"}';
}
?>



